package com.baize.minespace.controller;


import com.baize.minespace.pojo.Categories;
import com.baize.minespace.service.CategoriesService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 分类信息表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/categories")
public class CategoriesController {
    @Autowired
    private CategoriesService categoriesService;

    @ApiModelProperty("新增分类信息表")
    @ApiOperation(value = "新增分类信息表", notes = "新增分类信息表")
    @PostMapping("add")
    public Result<Boolean> addCategories(@RequestBody Categories categories){
        return Result.success(categoriesService.save(categories));
    }

    @ApiModelProperty("删除分类信息表")
    @ApiOperation(value = "删除分类信息表", notes = "删除分类信息表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deleteCategories(@PathVariable(value = "id") Integer id) {
        return Result.success(categoriesService.removeById(id));
    }

    @ApiModelProperty("修改分类信息表")
    @ApiOperation(value = "修改分类信息表", notes = "修改分类信息表")
    @PostMapping("update")
    public Result<Boolean> updateCategories(@RequestBody Categories categories) {
        return Result.success(categoriesService.updateById(categories));
    }

    @ApiModelProperty("查询分类信息表")
    @GetMapping("select/{id}")
    public Result<Categories> selectCategories(@PathVariable(value = "id") Integer id) {
        return Result.success(categoriesService.getById(id));
    }

    @ApiModelProperty("分页查询分类信息表")
    @ApiOperation(value = "分页查询分类信息表", notes = "分页查询分类信息表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<Categories>> selectCategoriesPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody Categories categories
    ) {
        return categoriesService.selectCategoriesPage(rows, page, categories);
    }
}
